package com.buka.role.controller;

import com.buka.common.ResultJson;
import com.buka.role.entity.Role;
import com.buka.role.service.RoleService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/role/getById")
public class GetById extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String id = req.getParameter("id");
        RoleService roleService = new RoleService();
        Role role = roleService.selectById(Long.parseLong(id));
        if(null == role){
            resp.getWriter().write(ResultJson.error());
        }else{
            resp.getWriter().write(ResultJson.success(role));
        }
    }
}
